package logic

import (
	"context"
	"zhihu/models/mysql"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProblemAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProblemAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProblemAddLogic {
	return &ProblemAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProblemAddLogic) ProblemAdd(in *zhihurpc.ProblemAddRequest) (*zhihurpc.ProblemAddResponse, error) {
	// todo: add your logic here and delete this line
	problem := mysql.Problem{
		Title:        in.Title,
		ProblemImage: in.ProblemImage,
		Hot:          int(in.Hot),
		UserId:       int(in.UserId),
	}
	mysql.DB.Debug().Create(&problem)

	return &zhihurpc.ProblemAddResponse{
		ProblemId: int64(problem.ID),
	}, nil
}
